<?php

class CompanyCardController extends BaseController
{

	/**
	 * 删除申请记录
	 * @param integer $id the ID of the model to be deleted
	 */
	public function actionDelete($id)
	{
		$this->loadModel($id)->delete();

		// if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
		if(!isset($_GET['ajax']))
			$this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin'));
	}

	/**
	 * 网铺审核管理
	 */
	public function actionAdmin()
	{
		$model=new CompanyCard('search');
		$model->unsetAttributes();  // clear any default values
		if(isset($_GET['CompanyCard']))
			$model->attributes=$_GET['CompanyCard'];

		$this->render('admin',array(
			'model'=>$model,
		));
	}

	/**
	 * 载入模型
	 * @param integer the ID of the model to be loaded
	 */
	public function loadModel($id)
	{
		$model=CompanyCard::model()->findByPk($id);
		if($model===null)
			throw new CHttpException(404,'The requested page does not exist.');
		return $model;
	}

	/**
	 * Performs the AJAX validation.
	 * @param CModel the model to be validated
	 */
	protected function performAjaxValidation($model)
	{
		if(isset($_POST['ajax']) && $_POST['ajax']==='company-card-form')
		{
			echo CActiveForm::validate($model);
			Yii::app()->end();
		}
	}
	
	/**
	 * 审核店铺信息
	 */
	public function actionCheckStatus($id){
		$model=$this->loadModel($id);
	
		// Uncomment the following line if AJAX validation is needed
		// $this->performAjaxValidation($model);
	
		if(isset($_POST['CompanyCard']))
		{
			$model->attributes=$_POST['CompanyCard'];
			$model->zoa_check_time = time();//审核时间为当前时间
			if($model->save())
				//成功跳转
				$this->redirect(array('admin'));
		}
	
		$this->render('checkinfo',array(
				'model'=>$model,
		));
	}
	
	/**
	 * 审核保证金信息
	 */
	public function actionCheckDeposit($id){
		$model=$this->loadModel($id);
	
		// Uncomment the following line if AJAX validation is needed
		// $this->performAjaxValidation($model);
	
		if(isset($_POST['CompanyCard']))
		{
			$model->attributes=$_POST['CompanyCard'];
			$model->zoa_deposit_check_time = time();//审核时间为当前时间
			if($model->save()){
				//成功跳转
				$this->redirect(array('admin'));
			}
		}
	
		$this->render('checkdeposit',array(
				'model'=>$model,
		));
	}
	
	/**
 	 * 代缴纳保障金
	 */
	public function actionSubmitDeposit($id){
		$model=$this->loadModel($id);
	
		// Uncomment the following line if AJAX validation is needed
		// $this->performAjaxValidation($model);
	

		
		if(isset($_POST['sure']))
		{
			$category = Category::model()->findByPk($model->zca_id);
			$model->zoa_deposit_status=2;
			$model->zoa_deposti=$category->zca_deposit;
			$model->zoa_deposit_time=time();//审核时间为当前时间
			if($model->save()){
				//成功跳转
				$this->redirect(array('admin'));
			}else{
				//失败跳转
				$this->render('../index/error',array('message'=>'对不起，保障金代缴失败，请稍后再试！'));
				exit;
			}
		}
	
		$this->render('sub_deposit',array(
				'model'=>$model,
		));
	}
}
